//
// Created by sjjmw on 3/24/2022.
//
#include "iostream"
#include "vector"
#include "list"
#include "algorithm"
#include "string"
#include "unordered_map"
#include "cmath"
#include<iomanip>
#include "string"
#include "map"
#include "list"

//一个升序，一个降序
struct Sol{

    void handle(int n,int r){
        int cost=0;
        std::vector<int> que_len(r);
        std::vector<int> times(n);
        for (int i = 0; i < n; ++i) {
            std::cin>>times[i];
        }
        std::sort(times.begin(),times.end());
        for(auto t:times){
            int minq=0;
            for (int i = 1; i < que_len.size(); ++i) {
                if(que_len[minq]>que_len[i]){
                    minq=i;
                }
            }
            que_len[minq]+=t;
            cost+=que_len[minq];
        }
        printf("%d\n",cost);
    }
};
int main(){
    int a,b,c;
    while(std::cin>>a>>b){
            Sol().handle(a,b);

    }

    return 0;
}